﻿using System;
using System.Data;
using System.Globalization;
using Pantry.Business;
using Pantry.Commons;

namespace Pantry.Web.Users
{
    public partial class ViewGovernmentOfficeRegion : System.Web.UI.Page
    {
        GovOfficeRegionBus _govOfficeRegionBus;
        CountyBus _countyBus;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                
                int govOfficeRegionId = int.Parse(Request.QueryString["ID"], CultureInfo.CurrentCulture);
                BindDropDownListCounty();
                LoadGovOfficeRegionById(govOfficeRegionId);
            }
        }

        private void LoadGovOfficeRegionById(int govOfficeRegionId)
        {
            try
            {
                _govOfficeRegionBus = new GovOfficeRegionBus();
                DataTable govOfficeRegion = _govOfficeRegionBus.GetGovOfficeRegionById(govOfficeRegionId);
                if (govOfficeRegion.Rows.Count > 0)
                {
                    TextBoxName.Text = govOfficeRegion.Rows[0]["GovOfficeRegionName"].ToString();
                    TextBoxDescription.Text = govOfficeRegion.Rows[0]["Description"].ToString();
                    DropDownListCounty.SelectedValue = govOfficeRegion.Rows[0]["CountyId"].ToString();
                }
            }
            catch (ApplicationException ex)
            {
                ExceptionHandler.WriteErrorLog(ex);
                Response.Write(ex.Message);
            }
        }
        private void BindDropDownListCounty()
        {
            try
            {
                _countyBus = new CountyBus();
                DataTable countyList = _countyBus.SelectAllCounty();
                DropDownListCounty.DataTextField = "CountyName";
                DropDownListCounty.DataValueField = "CountyId";
                DropDownListCounty.DataSource = countyList;
                DropDownListCounty.DataBind();
            }
            catch (ApplicationException ex)
            {
                ExceptionHandler.WriteErrorLog(ex);
            }
        }

        protected void ButtonBackClick(object sender, EventArgs e)
        {
            Response.Redirect("ViewListGovermentOfficeRegion.aspx");
        }

    }
}
